home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8381 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: ix.netcom.com!netnews
  2. From: judgemi@ix.netcom.com(Michael Judge )
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: new and delete with arrays
  5. Date: 17 Feb 1996 15:21:32 GMT
  6. Organization: Netcom
  7. Message-ID: <4g4rps$h71@ixnews5.ix.netcom.com>
  8. References: <4g4loa$i1l@mordred.gatech.edu>
  9. NNTP-Posting-Host: bos-ma10-19.ix.netcom.com
  10. X-NETCOM-Date: Sat Feb 17  7:21:32 AM PST 1996
  11.  
  12. In <4g4loa$i1l@mordred.gatech.edu> Darin Heuermann
  13. <gt1792a@prism.gatech.edu> writes: 
  14. >
  15. >When I allocate an array of classes with delete, should delete call
  16. all of 
  17. >the instances' destructors?  Here is an example of what I mean.
  18. >
  19. >//**********************************************
  20. >
  21. >class MYCLASS {
  22. >public:
  23. >   MYCLASS(void);
  24. >   ~MYCLASS(void);
  25. >} // MYCLASS
  26. >
  27. >MYCLASS *myClass;
  28. >
  29. >myClass = new MYCLASS[10];
  30. >delete myClass;
  31. >
  32. >//**********************************************
  33. >
  34. >I would expect all 10 instances to call ~MYCLASS() when delete myClass
  35. is 
  36. >called, but only the first instance's destructor is being called.  Is
  37. the 
  38. >a bug in the compiler or is this how it's supposed to work?
  39. >
  40. >-- Darin Heuermann
  41. >-- Virtual Software
  42.  
  43. You need to read a book here :)
  44.  
  45. use delete [] myClass
  46.  
  47. MJ
  48. judgemi@ix.netcom.com
  49.  
  50.